package com.tyf.common.util;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

/**
 * 
 * Description: 属性配置工具类
 * author:      mokeo
 * Createdate:  2016年9月18日下午9:21:32
 */
public final class PropertiesUtils implements EnvironmentAware{
	private static Environment environment;
	
	@Override
	public void setEnvironment(Environment environment) {
		PropertiesUtils.environment = environment;
	}
	
	public static boolean containsProperty(String key){
		return environment.containsProperty(key);
	}
	
	public static String getProperty(String key){
		return environment.getProperty(key);
	}
	
	public static String getProperty(String key, String defaultValue){
		return environment.getProperty(key, defaultValue);
	}
	
	public static <T>  T getProperty(String key, Class<T> targetType){
		return environment.getProperty(key, targetType);
	}
	
	public static String[] getActiveProfiles(){
		return environment.getActiveProfiles();
	}
	
	/**
	 * 获取当前激活的profile
	 * @return
	 */
	public static String getActiveProfile(){
		String[] profiles = environment.getActiveProfiles();
		if(profiles!=null && profiles.length>0){
			return profiles[0];
		}else{
			return "";
		}
	}
}
